package cn.edu.zut.pms.faker;

import com.github.javafaker.Faker;
import java.sql.*;
import java.util.Locale;
import java.util.Random;

public class FakerLogisticsGoodsFeedbackCnt {
    public static void main(String[] args) {
        // 数据库连接信息（请根据实际环境修改）
        String url = "jdbc:mysql://192.168.17.150:3306/soil?allowPublicKeyRetrieval=true&useSSL=false";
        String user = "root";
        String password = "000000";

        // 创建Faker实例
        Faker faker = new Faker(new Locale("zh_CN"));
        Random random = new Random();

        // 定义用户反馈类型（与源表dwd_logistics_data保持一致）
        String[] feedbacks = {"满意", "一般", "不满意", "未评价", "质量很好", "物流太慢", "包装破损"};

        try (Connection connection = DriverManager.getConnection(url, user, password)) {
            // 先清空表中现有数据（可选）
            String truncateSql = "TRUNCATE TABLE ads_logistics_goods_feedback_cnt";
            try (Statement statement = connection.createStatement()) {
                statement.execute(truncateSql);
            }

            // 插入数据的SQL语句
            String insertSql = "INSERT INTO ads_logistics_goods_feedback_cnt (" +
                    "product_feedback, quantity" +
                    ") VALUES (?, ?)";

            try (PreparedStatement preparedStatement = connection.prepareStatement(insertSql)) {
                for (String feedback : feedbacks) {
                    // 根据反馈类型的实际分布设置数量范围
                    int quantity;
                    switch (feedback) {
                        case "满意":
                        case "质量很好":
                            quantity = faker.number().numberBetween(8000, 15000); // 正面反馈占比最高
                            break;
                        case "未评价":
                            quantity = faker.number().numberBetween(5000, 10000); // 未评价数量次之
                            break;
                        case "一般":
                            quantity = faker.number().numberBetween(3000, 7000); // 中性反馈数量中等
                            break;
                        case "不满意":
                        case "物流太慢":
                        case "包装破损":
                            quantity = faker.number().numberBetween(1000, 4000); // 负面反馈数量较少
                            break;
                        default:
                            quantity = faker.number().numberBetween(2000, 5000);
                    }

                    // 设置参数
                    preparedStatement.setString(1, feedback);
                    preparedStatement.setInt(2, quantity);

                    preparedStatement.executeUpdate();
                }
                System.out.println("数据插入完成，共插入 " + feedbacks.length + " 条用户反馈数量记录");
            } catch (SQLException e) {
                e.printStackTrace();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}